package cn.iocoder.yudao.module.reading.controller.app.record.vo;

import cn.iocoder.yudao.module.reading.framework.vo.BaseUrlConvertVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 今日阅读记录 Response VO
 *
 * @author 芋道源码
 */
@Schema(description = "用户 APP - 今日阅读记录 Response VO")
@Data
@EqualsAndHashCode(callSuper = false)
public class TodayReadingRespVO extends BaseUrlConvertVO {

    @Schema(description = "今日阅读绘本数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "3")
    private Integer readBookCount;

    @Schema(description = "绘本列表")
    private List<TodayBookVO> bookList;

    @Schema(description = "今日阅读绘本")
    @Data
    public static class TodayBookVO {
        @Schema(description = "绘本ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
        private Long id;

        @Schema(description = "绘本标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "The Magic Key")
        private String title;

        @Schema(description = "封面图片URL", example = "https://example.com/book1.jpg")
        private String cover;

        @Schema(description = "阅读时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-01-06T09:30:00")
        private LocalDateTime readAt;

        @Schema(description = "阅读进度", example = "1.0")
        private Double readingProgress;

        @Schema(description = "是否完成", example = "true")
        private Boolean isCompleted;
    }

    /**
     * 转换URL字段
     * 将相对路径转换为完整URL
     */
    @Override
    public void convertUrls() {
        // 转换嵌套对象中的URL
        if (this.bookList != null) {
            this.bookList.forEach(book -> {
                book.cover = convertUrl(book.cover);
            });
        }
    }
}
